$(function () {
    //定义访问后台,获取头条列表以及一级列表的URL
    var url = '/person/index';
    getPersonInfo();
    //访问后台,获取头条列表以及一级列表类别列表
    $.getJSON(url,function (data) {
        console.log(data);
        //获取后台传递过来的头条列表
        var headLineList = data.headLineList;
        var swiperHtml = '';
        //遍历头条列表,并拼接出轮播图组
        headLineList.map(function (item,index) {
            swiperHtml += ''+'<div class="swiper-slide img-wrap">'
                +'<a href="/topic/topicContent?topicId='+item.topicId
                +'" external><img class="banner-img" src="'+item.topicImgList[0].imgAddr
                +'" alt="'+item.topicName+'"></a>'+'</div>';
        });
        //将轮播图组赋值给前端HTML组件
        $('.swiper-wrapper').html(swiperHtml);
        //设定轮播图轮换时间为3秒
        $('.swiper-container').swiper({
            autoplay:3000,
            //用户对轮播图进行操作时,是否自动停止autoplay
            autoplayDisableOnInteraction:false
        });
        //获取后台传递过来的大类类表
        var topicCategoryList = data.topicCategoryList;
        var categoryHtml = '';
        //遍历大类类表,拼接出两两一行的类别
        topicCategoryList.map(function (item,index) {
            categoryHtml += ''+'<div class="col-50 topic-classify" data-category='
                +item.topicCategoryId+'>'+'<div class="word">'
                +'<p class="topic-title">'+item.topicCategoryName
                +'</p>'+'<p class="topic-desc">'
                +item.topicCategoryDesc+'</p>'+'</div>'
                +'<div class="topic-classify-img-wrap">'
                +'<img class="topic-img" src="'+item.topicCategoryImg
                +'">'+'</div>'+'</div>';
        });
        //将拼接好的列表赋值给前端给前端Htlm控件
        $('.row').html(categoryHtml);
        //获取后台传递过来的用户信息
        // var person = data.person;
        // $('#headImg').attr('src',getContextPath()+person.headImg);
        // $('#username').html(person.username);
    });

    $('#me').click(function () {
        $.openPanel('#panel-left-demo');
    });

    $('.row').on('click','.topic-classify',function (e) {
        var topicCategoryId = e.currentTarget.dataset.category;
        var newUrl = '/topic/topicList?topicCategoryId='+topicCategoryId;
        window.location.href=newUrl;
    })


});

